package org.springblogs.generate;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.springblogs.generate.tpl.ProjectTemplate;

public class GenerateProject {
	private static final String basePath = "E:\\study\\workspace\\springblogs\\";
	//  "springblogs-core", "springblogs-model", "springblogs-utils", "springblogs-web", "springblogs-service", "springblogs-dao", 
	private static final String[] modules = new String[] {"springblogs-batch",};

	public static void main(String[] args) {
		try {
			genProject();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static void genProject() throws IOException {

		for (String module : modules) {
			System.out.println("generate : " + module);
			String path = String.format("%1$s\\src\\main\\java\\org\\springblogs\\%2$s", module, module.substring(12));
			File file = new File(basePath, path);
			if(!file.exists()){
				file.mkdirs();
			}
			
			FileWriter fw = new FileWriter(new File(basePath, module + "\\pom.xml"));
			fw.write(String.format(ProjectTemplate.TPL_POM_XML, module));
			fw.close();
			
			fw = new FileWriter(new File(basePath, module + "\\.gitignore"));
			fw.write(ProjectTemplate.TPL_DOT_GITIGNORE);
			fw.close();
		}
		System.out.println("finish");
	}
}
